package dk.au.cs.bdsi.mail.domain;

import java.util.LinkedList;
import java.util.List;
import static dk.au.cs.bdsi.mail.domain.HeaderBuilder.header;

public class MailBuilder implements Builder<Mail> {
	public static MailBuilder message() {
		return new MailBuilder();
	}
	
	private String to = "foo@domain.com";
	private String from = "bar@domain.com";
	private String subject = "Hello World";
	private String body = "Got milk?";
	private List<Header> headers = null;
	private MailStatus status = MailStatus.Pending;
	
	@Override
	public Mail build() {
		if (headers == null) {
			headers = new LinkedList<Header>();
			headers.add(header().build());
		}
		return new Mail(to, from, subject, body, status, headers);
	}
	
	@SuppressWarnings("hiding")
	public MailBuilder to(String to) {
		this.to = to;
		return this;
	}
	
	@SuppressWarnings("hiding")
	public MailBuilder from(String from) {
		this.from = from;
		return this;
	}
	
	@SuppressWarnings("hiding")
	public MailBuilder withSubject(String subject) {
		this.subject = subject;
		return this;
	}
	
	@SuppressWarnings("hiding")
	public MailBuilder withBody(String body) {
		this.body = body;
		return this;
	}
	
	@SuppressWarnings("hiding")
	public MailBuilder withHeaders(List<Header> headers) {
		this.headers = headers;
		return this;
	}
	
	public MailBuilder withHeader(Header header) {
		if (headers == null) 
			headers = new LinkedList<Header>();
		this.headers.add(header);
		return this;
	}
	
	@SuppressWarnings("hiding")
	public MailBuilder withStatus(MailStatus status) {
		this.status = status;
		return this;
	}
}
